<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: czq
  Date: 2018/5/16
  Time: 11:57
  To change this template use File | Settings | File Templates.
--%>
<%@page pageEncoding="UTF-8" language="java" %>
<%@ include file="/commons/global.jsp"%>
<html>
<head>
    <title>编辑超级管理员</title>
    <script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/respond.min.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/css/style.css" />
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
</head>
<body>
    <article class="cl pd-20">
        <form  method="post" action="<%=request.getContextPath()%>/manage/user/updatePassword" id="userForm" class="form form-horizontal" >
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>原密码密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="oldPassword" name="oldPassword">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>新密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" value="${userVo.id}" id="id" hidden>
                    <input type="text" class="input-text" value="" placeholder="" id="password" name="password">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="rePassword" name="rePassword">
                </div>
            </div>
            <div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-6">
					<button id="passwordBtn" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
					<button id="cancel" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
				</div>
			</div>
        </form>
    </article>
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery/1.9.1/jquery.min.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/layer/2.4/layer.js"></script> 
<%-- 	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/icheck/jquery.icheck.min.js"></script>  --%>
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/h-ui/js/H-ui.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/h-ui.admin/js/H-ui.admin.page.js"></script> 
	<script type="text/javascript">
		$("#cancel").click(function(){
			parent.layer.close(parent.index);
		});

		function validateOldPassword(){
            var validateOldPassword = 0;
            var oldPassword = $("#oldPassword").val();
            $.ajax({
                url:'<%=request.getContextPath()%>/manage/user/validatePassword',
                type:'post',
                async:false,
                data:{"password": oldPassword},
                dataType:'json',
                success:function(data){
                    validateOldPassword = data;
                },fail:function(){
                }
            });

            return validateOldPassword;
        }


		$("#passwordBtn").click(function(){
		    var password = $("#password").val();
		    var rePassword = $("#rePassword").val();
            var id = $("#id").val();

            var oldPassword = $("#oldPassword").val();
            if(oldPassword.length == 0){
                top.layer.open({
                    icon: 1,
                    content: "原密码不能为空！",
                    time: 1500
                });
                return false;//退出检测函数
            }

           var validatePassword = validateOldPassword();
            if(validatePassword == 0){
                top.layer.open({
                    icon: 1,
                    content: "原密码错误！",
                    time: 1500
                });
                return false;
            }

		    if(password.length == 0){
                top.layer.open({
                    icon: 1,
                    content: "密码不能为空！",
                    time: 1500
                });
		        return false;
            }

            if(rePassword.length == 0){
                top.layer.open({
                    icon: 1,
                    content: "确认密码不能为空！",
                    time: 1500
                });
		        return false;
            }

		    if(password != rePassword){
                top.layer.open({
                    icon: 1,
                    content: "两次密码不一样",
                    time: 1500
                });
		        return false;
            }

            $.ajax({
                url:'<%=request.getContextPath()%>/manage/user/updatePassword',
                type:'post',
                data:{"oldPassword":oldPassword, "password": password},
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        top.layer.open({
                            icon: 1,
                            content: "修改成功！",
                            time: 1500
                        });
                        logout();
                    }else{

                    }
                }
            });
		})

        function logout(){
            $.ajax({
                url:'<%=request.getContextPath()%>/login/logout',
                type:'POST',
                dataType:'json',
                success:function(data){
                    window.top.location.href = '${rootPath }/login/loginUI';
                }
            });
        }
	</script>
</body>
</html>
